package com.atguigu.map;
import org.junit.Test;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class MapTest2 {
    //Set keySet():返回所有key构成的Set集合
    //Collection values():返回所有value构成的Collection集合
    //Set entrySet():返回所有key-value对构成的Set集合
    @Test
    public void test(){
        Map map=new HashMap();
        map.put("AA",123);
        map.put(45,123);
        map.put("BB",456);
        //遍历所有的key集:keySet
        Iterator iterator = map.keySet().iterator();
        while(iterator.hasNext()){
            System.out.print(iterator.next()+"  ");
        }
        System.out.println();
        //遍历所有的value集:values
        Iterator iterator1 = map.values().iterator();
        while(iterator1.hasNext()){
            System.out.print(iterator1.next()+"  ");
        }
        //遍历所有的key-value
        Iterator iterator2 = map.entrySet().iterator();
        while(iterator2.hasNext()){
            System.out.print(iterator2.next()+"  ");
        }
    }
}
